/**
 * Created by dongdh on 2016/8/10.
 */

var checkOrderTimes = 20 * 10;  //每分钟20次
var checkOrderResult = 3 ; //默认进行中

$(function(){
    checkOrderStatusTimes();
});



function checkOrderStatusTimes(){
    checkOrderTimes--;

    if (checkOrderResult == 1 || checkOrderResult == 2 ) {
        //成功 或 失败
        clearTimeout(ost);

        window.location.href = ctx + "/scan/wallet/result.shtml?orderId=" + $("#orderId").val() + "&orderKey=" + $("#orderKey").val();

    } else if (checkOrderResult == 3) {
        //进行中
        getOrderStatus();
    }
    //console.log(checkOrderTimes);
    ost = setTimeout(checkOrderStatusTimes, 3000);
    if ( checkOrderTimes <= 0 ){
        clearTimeout(ost);
    }
}


/**
 * 获取订单状态
 */
function getOrderStatus() {

    $.ajax({
        url:ctx+"/pay/getOrderResult.shtml?"+(new Date()).getTime(),
        async:false,
        type:"GET",
        dataType:"JSON",
        data:{orderId: $("#orderId").val()}
    }).done(function(data){
        checkOrderResult = data.result;
    });
}